package com.ruoyi.system.designpattern.visitor;

// 具体访问者：计算价格
public class ShoppingCartVisitor implements Visitor {
    
    @Override
    public void visit(Book book) {
        double price = book.getPrice();
        // 书籍有10%折扣
        if (book.getPrice() > 50) {
            price = price * 0.9;
        }
        System.out.printf("Book: %s, Price: %.2f%n", book.getName(), price);
    }
    
    @Override
    public void visit(CD cd) {
        double price = cd.getPrice();
        // CD有5%折扣
        price = price * 0.95;
        System.out.printf("CD: %s, Price: %.2f%n", cd.getName(), price);
    }
    
    @Override
    public void visit(DVD dvd) {
        double price = dvd.getPrice();
        // DVD无折扣，但有10元服务费
        price += 10;
        System.out.printf("DVD: %s, Price: %.2f%n", dvd.getName(), price);
    }
}
